\defmodule {ContinuousDistribution2Dim}

Classes implementing 2-dimensional continuous distributions should inherit 
from this class.
Such distributions are characterized by a \emph{density} function $f(x, y)$;
thus the signature of a \texttt{density} method is supplied here.
This class also provides a default implementation of $\overline F(x, y)$, 
the upper \texttt{CDF}. The inverse function $F^{-1}(u)$ represents a curve
$y = h(x)$ of constant $u$ and it is not implemented.

\bigskip\hrule

\begin{code}
\begin{hide}
/*
 * Class:        ContinuousDistribution2Dim
 * Description:  Mother class 2-dimensional continuous distributions
 * Environment:  Java
 * Software:     SSJ 
 * Copyright (C) 2001  Pierre L'Ecuyer and Universite de Montreal
 * Organization: DIRO, Universite de Montreal
 * @author       
 * @since

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   <a href="http://www.gnu.org/licenses">GPL licence site</a>.
 */
\end{hide}
package umontreal.iro.lecuyer.probdistmulti;
\begin{hide}
import umontreal.iro.lecuyer.util.PrintfFormat;
import umontreal.iro.lecuyer.util.Num;
\end{hide}

public abstract class ContinuousDistribution2Dim
                          extends ContinuousDistributionMulti\begin{hide} {\end{hide}

   public int decPrec = 15;
\end{code}
\begin{tabb} Defines the target number of decimals of accuracy when
 approximating a distribution function, but there is \emph{no guarantee} that
 this target is always attained.
\end{tabb}
\begin{code} \begin{hide}

    // x infinity for some distributions
     protected static final double XINF = Double.MAX_VALUE;  

    // x infinity for some distributions                                       
    protected static final double XBIG = 1000.0;  

    // EPSARRAY[j]: Epsilon required for j decimal degits of precision
    protected static final double[] EPSARRAY = {
    0.5, 0.5E-1, 0.5E-2, 0.5E-3, 0.5E-4, 0.5E-5, 0.5E-6, 0.5E-7, 0.5E-8,
    0.5E-9, 0.5E-10, 0.5E-11, 0.5E-12, 0.5E-13, 0.5E-14, 0.5E-15, 0.5E-16,
    0.5E-17, 0.5E-18, 0.5E-19, 0.5E-20, 0.5E-21, 0.5E-22, 0.5E-23, 0.5E-24,
    0.5E-25, 0.5E-26, 0.5E-27, 0.5E-28, 0.5E-29, 0.5E-30, 0.5E-31, 0.5E-32,
    0.5E-33, 0.5E-34, 0.5E-35
    };\end{hide}

   public abstract double density (double x, double y);
\end{code}
\begin{tabb} Returns $f(x, y)$, the density of $(X, Y)$ evaluated at $(x, y)$.
\end{tabb}
\begin{htmlonly}
   \param{x}{value $x$ at which the density is evaluated}
   \param{y}{value $y$ at which the density is evaluated}
   \return{density function evaluated at $(x, y)$
\end{htmlonly}
\begin{code}

   public double density (double[] x)\begin{hide} {
      if (x.length != 2)
         throw new IllegalArgumentException("x must be in dimension 2");

      return density (x[0], x[1]);
   }\end{hide}
\end{code}
\begin{tabb} Simply calls \texttt{density (x[0], x[1])}.
\end{tabb}
\begin{htmlonly}
   \param{x}{point $(x[0], x[1])$ at which the density is evaluated}
   \return{density function evaluated at $(x[0], x[1])$
\end{htmlonly}
\begin{code}

   public abstract double cdf (double x, double y); \end{code}
 \begin{tabb} Computes the distribution function $F(x, y)$: 
 \eq
   F(x, y) = P[X\le x, Y \le y] =
    \int_{-\infty}^x ds \int_{-\infty}^y dt\, f(s, t).
 \endeq
 \end{tabb}
 \begin{htmlonly}
    \param{x}{value $x$ at which the distribution function is evaluated}
    \param{y}{value $y$ at which the distribution function is evaluated}
    \return{distribution function evaluated at  $(x, y)$
 \end{htmlonly}
\begin{code}

   public double barF (double x, double y) \begin{hide} {
      double u = 1.0 + cdf (x, y) - cdf (XINF, y) - cdf (x, XINF);
      if (u <= 0.0) return 0.0;
      if (u >= 1.0) return 1.0;
      return u;
   }\end{hide}
\end{code}
 \begin{tabb} Computes  the upper cumulative distribution function
  $\overline F(x, y)$:
 \eq
   \overline F(x, y) = P[X\ge x, Y \ge y] =
    \int^{\infty}_x ds \int^{\infty}_y dt\, f(s, t).
 \endeq
%    The default implementation computes 
%   $\overline F(x, y) = 1 - F(\infty, y) - F(x, \infty) + F(x, y)$.
 \end{tabb}
\begin{htmlonly}
   \param{x}{value $x$ at which the upper distribution is evaluated}
   \param{y}{value $y$ at which the upper distribution is evaluated}
   \return{upper distribution function evaluated at  $(x, y)$
\end{htmlonly}
\begin{code}

   public double cdf (double a1, double a2, double b1, double b2) \begin{hide} {
      if (a1 >= b1 || a2 >= b2) return 0.0;
      return cdf (b1, b2) - cdf (a1, b2) - cdf (b1, a2) + cdf(a1, a2);
   }\end{hide}
\end{code}
 \begin{tabb} Computes the cumulative probability in the square region
 \eq
  P[a_1 \le X \le b_1,\: a_2 \le Y \le b_2] =
    \int_{a_1}^{b_1} dx \int_{a_2}^{b_2} dy\, f(x, y).
 \endeq 
 \end{tabb}
\begin{htmlonly}
   \param{a1}{$x$ lower limit of the square}
   \param{a2}{$y$ lower limit of the square}
   \param{b1}{$x$ upper limit of the square}
   \param{b2}{$y$ upper limit of the square}
   \return{the cumulative probability in the square region}
\end{htmlonly}
\begin{code}
\begin{hide}
}\end{hide}
\end{code}
